package decorator.example;

/**
 *
 * 设有两个程序员他们原来只会各自的技能，
 * 现在需要让Android程序猿具备设计模式技能，那就给他装饰一下。如下实现：
 * Created by yangliwei on 2018/3/19.
 */
//Component（抽象构件）
interface ProgramMonkey {
    void skills();
}

//ConcreteComponent（具体构件）
class AndroidProgramMonkey implements ProgramMonkey {
    @Override
    public void skills() {
        System.out.println("会写Android代码！");
    }
}

//ConcreteComponent（具体构件）
class PHPProgramMonkey implements ProgramMonkey {
    @Override
    public void skills() {
        System.out.println("会写PHP代码！");
    }
}

//Decorator（抽象装饰类）
class ProgramMonkeyDecorator implements ProgramMonkey {
    protected ProgramMonkey mProgramMonkey;

    public ProgramMonkeyDecorator(ProgramMonkey mProgramMonkey) {
        this.mProgramMonkey = mProgramMonkey;
    }

    public void skills() {
        mProgramMonkey.skills();
    }
}

//ConcreteDecorator（具体装饰类）
class PatternDecorator extends ProgramMonkeyDecorator {
    public PatternDecorator(ProgramMonkey mProgramMonkey) {
        super(mProgramMonkey);
    }

    @Override
    public void skills() {
        super.skills();
        System.out.println("会设计模式！");
    }
}

public class Main {
    public static void main(String[] args) {
        //有一个Android程序猿只会写Android代码
        ProgramMonkey programMonkey = new AndroidProgramMonkey();
        programMonkey.skills();
        //装饰一下他，装逼的技能，他竟然除了写Android还懂设计模式   有点类似与InputStream的构造
        programMonkey = new PatternDecorator(programMonkey);
        programMonkey.skills();

        programMonkey = new PHPProgramMonkey();
        programMonkey.skills();
    }
}